<?php
class DepartmentModel extends Model{
	
	private $department_cows='a.`department_id`, a.`department_name`, a.`local_id`, a.`building_id`, a.`floor_id`';
	
	public function get_department_by_uid($uid){
		$sql ='select '.$this->department_cows.' from audience_department as a';
		$sql.=' join audience as b on b.audience_department=a.department_id';
		$sql.=' where b.audience_id='.$uid;
		$sql.=' limit 1';
		$rs=M('audience_department','','DB_MEETING')->query($sql);		
		return $rs[0];
	}
	
	public function get_department_personel($uid){
		$sql ='select personnel_id from department_personnel as a';
		$sql.=' join audience as b on b.audience_department=a.department_id';
		$sql.=' where b.audience_id='.$uid;
		$sql.=' limit 1';
		$rs=M('department_personnel','','DB_MEETING')->query($sql);
		return $rs[0]['personnel_id'];
	}

	public function get_audience_num($department_id)
	{
		$num = $this->get_son_department_num($department_id);
		$num+= $this->get_son_audience($department_id);
		return $num;
	}

	public function get_son_department_num($department_id)
	{
		return M('audience_department','','DB_MEETING')->where('time_insert > time_delete and department_pid = '.$department_id)->count();
	}

	public function get_son_audience($department_id)
	{
		return M('audience','','DB_MEETING')->where('time_insert > time_delete and audience_department = '.$department_id)->count();
	}
}

?>